package linkedlist.create;

import linkedlist.Node;

import java.util.List;

/**
 * @Author wangtengyu
 * @Create 2018-09-03-9:27 循环创建链表
 */
public class LoopLinkedCreator {


  public Node createlinkedList(List datalList) {

    if (datalList.isEmpty()) {
      return null;
    }

    Node prev = null;
    Node head = null;

    for (int i = 0; i < datalList.size(); i++) {
      Node node = new Node(datalList.get(i));
      if (prev == null) {
        head = node;
      } else {
        prev.setNext(node);
      }
      prev = node;
    }
    return head;

  }
}
